package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallUserLevelModel;
import com.mallcloud.mall.mall.service.MallUserLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-用户等级")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/userLevel")
public class MallUserLevelController {
	private final MallUserLevelService userLevelService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_view')")
	public R page(Page page, MallUserLevelModel usersLevelModel) {
		return R.ok(userLevelService.page(page, Wrappers.query(usersLevelModel)));
	}

	@ApiOperation("查询详情")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(userLevelService.getById(id));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_add')")
	public R save(@RequestBody MallUserLevelModel usersLevelModel) {
		return R.ok(userLevelService.save(usersLevelModel));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_edit')")
	public R updateById(@RequestBody MallUserLevelModel usersLevelModel) {
		return R.ok(userLevelService.updateById(usersLevelModel));
	}

	@ApiOperation("删除")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_del')")
	public R removeById(@PathVariable String id) {
		return R.ok(userLevelService.removeById(id));
	}

	@ApiOperation("批量删")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('mall_userlevel_del')")
	public R removeByIds(@RequestBody List<String> ids) {
		return R.ok(userLevelService.removeBatchByIds(ids));
	}

	@ApiOperation("导出")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_userlevel_export')")
	public List<MallUserLevelModel> export(MallUserLevelModel usersLevelModel) {
		return userLevelService.list(Wrappers.query(usersLevelModel));
	}
}
